package com.hxgis.oc.controller;

import cn.hutool.http.HttpUtil;
import com.hxgis.auw.ApiWrapIgnore;
import com.hxgis.oc.config.CmaConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/cma")
public class CmaController {
    @ApiWrapIgnore
    @ResponseBody
    @GetMapping(value = { "/api" }, produces="application/json;charset=UTF-8")
    public Object getJson(HttpServletRequest request, HttpServletResponse response) {
        String query = request.getQueryString();
        if(!query.isEmpty())
        {
            String url = CmaConfig.getConfig().getBaseUrl() + "/api?" + query;
            return HttpUtil.get(url);
        }
        response.setStatus(404);
        return null;
    }
}
